package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.MesPmTask;
import com.ruoyi.mes.service.IMesPmTaskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预装生产计划Controller
 * 
 * @author Elon
 * @date 2023-09-02
 */
@RestController
@RequestMapping("/mes/task")
public class MesPmTaskController extends BaseController
{
    @Autowired
    private IMesPmTaskService mesPmTaskService;

    /**
     * 查询预装生产计划列表
     */
    @PreAuthorize("@ss.hasPermi('mes:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(MesPmTask mesPmTask)
    {
        startPage();
        List<MesPmTask> list = mesPmTaskService.selectMesPmTaskList(mesPmTask);
        return getDataTable(list);
    }

    /**
     * 导出预装生产计划列表
     */
    @PreAuthorize("@ss.hasPermi('mes:task:export')")
    @Log(title = "预装生产计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesPmTask mesPmTask)
    {
        List<MesPmTask> list = mesPmTaskService.selectMesPmTaskList(mesPmTask);
        ExcelUtil<MesPmTask> util = new ExcelUtil<MesPmTask>(MesPmTask.class);
        util.exportExcel(response, list, "预装生产计划数据");
    }

    /**
     * 获取预装生产计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:task:query')")
    @GetMapping(value = "/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") Long taskId)
    {
        return success(mesPmTaskService.selectMesPmTaskByTaskId(taskId));
    }

    /**
     * 新增预装生产计划
     */
    @PreAuthorize("@ss.hasPermi('mes:task:add')")
    @Log(title = "预装生产计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesPmTask mesPmTask)
    {
        return toAjax(mesPmTaskService.insertMesPmTask(mesPmTask));
    }

    /**
     * 修改预装生产计划
     */
    @PreAuthorize("@ss.hasPermi('mes:task:edit')")
    @Log(title = "预装生产计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesPmTask mesPmTask)
    {
        return toAjax(mesPmTaskService.updateMesPmTask(mesPmTask));
    }

    /**
     * 删除预装生产计划
     */
    @PreAuthorize("@ss.hasPermi('mes:task:remove')")
    @Log(title = "预装生产计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{taskIds}")
    public AjaxResult remove(@PathVariable Long[] taskIds)
    {
        return toAjax(mesPmTaskService.deleteMesPmTaskByTaskIds(taskIds));
    }
}
